package design.singleton;

import java.io.ObjectStreamException;
import java.io.Serializable;

/**
 * 只有当调用getInstance()方法时，才会加载Singleton1Builder并且为INSTANCE分配内存并赋值。
 * 所有静态属性只会赋值一次。
 *
 * @author yuqi<307530884@qq.com> <2017/3/23>
 * @version 1.0
 * @since 1.0
 */
public class Singleton1 implements Serializable {

	private static final long serialVersionUID = 8044360747745658090L;

	private Singleton1(){}

    public static Singleton1 getInstance(){
        return Singleton1Builder.INSTANCE;
    }

    private static class Singleton1Builder {
        public final static Singleton1 INSTANCE = new Singleton1();
    }

    private Object readResolve() throws ObjectStreamException {
        return Singleton1Builder.INSTANCE;
    }

}
